<!--
  * 提现
  *
  * @Author:    syf
  * @Date:      2025-05-29 11:07:16
  * @Copyright  畅想科技
-->
<template>
  <a-modal
      :title="form.recordId ? '编辑' : '添加'"
      width="500px"
      :open="visibleFlag"
      @cancel="onClose"
      :maskClosable="false"
      :destroyOnClose="true"
  >
    <a-form ref="formRef" :model="form" :rules="rules" :label-col="{ span: 7 }" >
          <a-row>
                    <a-form-item label="记录ID"  name="recordId">
                      <a-input style="width: 100%" v-model:value="form.recordId" placeholder="记录ID" />
                    </a-form-item>
                    <a-form-item label="提现申请id"  name="txId">
                      <a-input style="width: 100%" v-model:value="form.txId" placeholder="提现申请id" />
                    </a-form-item>
                    <a-form-item label="支付金额"  name="amount">
                      <a-input style="width: 100%" v-model:value="form.amount" placeholder="支付金额" />
                    </a-form-item>
                    <a-form-item label="支付方式"  name="paymentType">
                      <a-input style="width: 100%" v-model:value="form.paymentType" placeholder="支付方式：微信，支付宝" />
                    </a-form-item>
                    <a-form-item label="支付状态"  name="status">
                      <a-input style="width: 100%" v-model:value="form.status" placeholder="支付状态" />
                    </a-form-item>
                    <a-form-item label="支付时间"  name="paymentTime">
                      <a-date-picker show-time valueFormat="YYYY-MM-DD HH:mm:ss" v-model:value="form.paymentTime" style="width: 100%" placeholder="支付时间" />
                    </a-form-item>
                    <a-form-item label="返回值"  name="returnMsg">
                      <a-input style="width: 100%" v-model:value="form.returnMsg" placeholder="支付状态返回值" />
                    </a-form-item>
                    <!-- <a-form-item label="0:未删除；1:删除"  name="isDel">
                      <BooleanSelect v-model:value="form.isDel" style="width: 100%" />
                    </a-form-item> -->
                    <!-- <a-form-item label="创建人，如管理员"  name="createBy">
                      <a-input style="width: 100%" v-model:value="form.createBy" placeholder="创建人，如管理员" />
                    </a-form-item> -->
                    <!-- <a-form-item label="创建时间"  name="createTime">
                      <a-date-picker show-time valueFormat="YYYY-MM-DD HH:mm:ss" v-model:value="form.createTime" style="width: 100%" placeholder="创建时间" />
                    </a-form-item>
                    <a-form-item label="信息更改人员"  name="updateBy">
                      <a-input style="width: 100%" v-model:value="form.updateBy" placeholder="信息更改人员" />
                    </a-form-item>
                    <a-form-item label="信息修改时间"  name="updateTime">
                      <a-date-picker show-time valueFormat="YYYY-MM-DD HH:mm:ss" v-model:value="form.updateTime" style="width: 100%" placeholder="信息修改时间" />
                    </a-form-item> -->
          </a-row>

    </a-form>

    <template #footer>
      <a-space>
        <a-button @click="onClose">取消</a-button>
        <a-button type="primary" @click="onSubmit">保存</a-button>
      </a-space>
    </template>
  </a-modal>
</template>
<script setup>
  import { reactive, ref, nextTick } from 'vue';
  import _ from 'lodash';
  import { message } from 'ant-design-vue';
  import { SmartLoading } from '/@/components/framework/smart-loading';
  import { recordApi } from '/@/api/business/record/record-api';
  import { smartSentry } from '/@/lib/smart-sentry';
          import BooleanSelect from '/@/components/framework/boolean-select/index.vue';

  // ------------------------ 事件 ------------------------

  const emits = defineEmits(['reloadList']);

  // ------------------------ 显示与隐藏 ------------------------
  // 是否显示
  const visibleFlag = ref(false);

  function show(rowData) {
    Object.assign(form, formDefault);
    if (rowData && !_.isEmpty(rowData)) {
      Object.assign(form, rowData);
    }
    visibleFlag.value = true;
    nextTick(() => {
      formRef.value.clearValidate();
    });
  }

  function onClose() {
    Object.assign(form, formDefault);
    visibleFlag.value = false;
  }

  // ------------------------ 表单 ------------------------

  // 组件ref
  const formRef = ref();

  const formDefault = {
          recordId: undefined,
              recordId: undefined, //记录ID
              txId: undefined, //提现申请id
              amount: undefined, //支付金额
              paymentType: undefined, //支付方式：微信，支付宝
              status: undefined, //支付状态：pending：未处理 success：支付成功 failed：支付失败
              paymentTime: undefined, //支付时间
              returnMsg: undefined, //支付状态返回值
              isDel: undefined, //0:未删除；1:删除
              createBy: undefined, //创建人，如管理员
              createTime: undefined, //创建时间
              updateBy: undefined, //信息更改人员
              updateTime: undefined, //信息修改时间
  };

  let form = reactive({ ...formDefault });

  const rules = {
  };

  // 点击确定，验证表单
  async function onSubmit() {
    try {
      await formRef.value.validateFields();
      save();
    } catch (err) {
      message.error('参数验证错误，请仔细填写表单数据!');
    }
  }

  // 新建、编辑API
  async function save() {
    SmartLoading.show();
    try {
      if (form.recordId) {
        await recordApi.update(form);
      } else {
        await recordApi.add(form);
      }
      message.success('操作成功');
      emits('reloadList');
      onClose();
    } catch (err) {
      smartSentry.captureError(err);
    } finally {
      SmartLoading.hide();
    }
  }

  defineExpose({
    show,
  });
</script>
